<?php
$res = http_post('https://developer.toutiao.com/auth/entity/add_role', [
    "access_token" => getAccessToken(),
    "appid" => "ttdd96ab2b42a07b6d01",
    "entity_id"=>"E_7383974744783110194",
    "industry_role" => 2,
    "institution_role_info" => [
        "institution_info" => [
            "record_name" => "萍乡市蓝盾实业有限公司机动车驾驶员培训中心",
            "scene_type" => "线下机构",
            "subject_type" => "企业工商户",
            "logo_uri" => "certification/resource/35337566849cee5f43a5550631819b60",
            "trademark_uri" => "certification/resource/35337566849cee5f43a5550631819b60",
            "desc" => "萍乡市蓝盾实业有限公司机动车驾驶员培训中心"
        ],
        "institution_class_info" => [
            "industry_class" => [
                "material_type" => 0,
                "material_expiretime" => "",
                "material_paths" => [""]
            ],
            "employee" => [
                "employee_material" => [
                    "name" => "何亮",
                    "id_number" => "360302198409243014",
                    "expire_time" => "2036-09-01",
                    "front_path" => "certification/resource/c88b63b25e96ecf19a3bf4bebbb44b1a",
                    "back_path" => "certification/resource/6960f959db9f8a6108c048318826b255"
                ],
                "cooperation_agreement" => [
                    "material_type" => 1005,
                    "material_expiretime" => "2031-06-06",
                    "material_paths" => [
                        "certification/resource/3f95f413f927f68b5b81a86ee9c38e60"
                    ]
                ]
            ],
            "class_material" => [
                "material_type" => 1001,
                "material_expiretime" => "2031-06-06",
                "material_paths" => [
                    "certification/resource/a18ec8cfffc36ae07f9497ccbe140ab9"
                ]
            ]
        ]
    ],
    //合作协议 certification/resource/3f95f413f927f68b5b81a86ee9c38e60





]);
//product/resource/2e5e2f178fb03db1eb9dae48e7d91505
//tos-cn-i-b2i6zad4el/75c0dac568b9f4d8c69031b1957a8264
echo $res;
exit;
function get_access_token()
{
    $access_token = json_decode(http_post("https://developer.toutiao.com/api/apps/v2/token", [
        "appid" => "ttdd96ab2b42a07b6d01",
        "grant_type" => "client_credential",
        "secret" => "028db66bdff3fa44cad6f2fafa1faa3d6571b3b4"
    ]), true)['data']['access_token'];
    return $access_token;
}
function getAccessToken()
{
    //检测文件是否存在
    $file = 'access_token.txt';
    if (file_exists($file)) {
        //获取文件的最后修改时间
        $mtime = filemtime($file);
        //获取当前时间
        $now = time();
        //判断是否过期
        if (($now - $mtime) < 300) {
            //未过期，直接读取文件内容
            $access_token = file_get_contents($file);
            return $access_token;
        } else {
            $access_token = get_access_token();
            file_put_contents($file, $access_token);
            return $access_token;

        }
    } else {
        $access_token = get_access_token();
        file_put_contents($file, $access_token);
        return $access_token;
    }
}
function http_post($url, $data)
{
    $postdata = json_encode($data);
    // echo ($postdata);
    // exit;



    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/json',
            'content' => $postdata,
            'timeout' => 15 * 60
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}